package model;

import java.util.Random;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Scanner;

//might create another class for importing words

public class logManager {
	
	private ArrayList<String> word = new ArrayList<String>();
	protected ArrayList<log> logs = new ArrayList<log>();
	private Random generator = new Random(System.currentTimeMillis());
	private int index;
	
	
	//import words from text file
	//create logs by choosing word from list
	
	public logManager() {
		
		importWords(); 
		
		//choose words for level
		
		for (int i = 0; i < 25; i++) {
			index = generator.nextInt(word.size());
			logs.add(new log(word.get(index)));
			
			//Note: are we going to have each log as the same size or have different sizes for each log?
			logs.get(i).setDim(100, 40);
			
			//set positions of logs
			logs.get(i).setPos(100+(i%5)*240, (i/5+1)*80);
			
			//set velocity of logs
			logs.get(i).setVelocityX((int) (Math.pow(-1,i/5)*10) );
			}
		
		testPrintInfo();
		}

			
	
	public void testPrintInfo() {
		for (int i = 0; i < 25; i++) {
			System.out.println("index: " + i + ", PosX: " + logs.get(i).getPosX() + ", PosY: " + logs.get(i).getPosY() + ", VelX: " + logs.get(i).getVelocityX());
		}
			
		
	}



	//import words from text file
	//perhaps change for whatever state we're in, to select words from different
	//text file
	public void importWords() {
		
	    FileReader reader;
	    
		try {
			reader = new FileReader("words.txt");
		    Scanner in = new Scanner(reader);

		    while (in.hasNextLine()) {
		    	String line = in.nextLine();
		    	word.add(line);
		    }
		    
		    in.close();
		    
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		

	}
	
	public void viewLogWords() {
		System.out.println("[-----RANDOM WORDS-----]");
		for (int i = 0; i < logs.size(); i++) {
			System.out.println(logs.get(i).getWord());
		}
	}
	
	//mutator of the logs position...this will be called by the controller
	//on ticks of the timer
	
	//we need a way to wrap the log around when it leaves the screen, 
	//relative to another log
	public void moveLogs(long time) {
		for (int i = 0; i < logs.size(); i++)
			logs.get(i).move(time);
	}

	public  ArrayList<log> getLogList() {
		return logs;
		
	}


}
